#include "netdisk3.h"

int getsFunc(const char* user, const char* arg, int curr_folder, int netfd, MYSQL* mysql){
    int realId = getAbsolutePathId(curr_folder, arg, user, mysql);
    int ret = 0;
    char name[4096] = {0};
    printf("realId = %d\n", realId);
    if(realId == -1){
        ret = realId;
    }else{
        char sql[4096] = {0};
        sprintf(sql, "select * from virtual_file where tomb = 0 "
                "and id = %d and type = 'f';", realId);
        int Mret = mysql_query(mysql, sql);
        MYSQL_QUERY_CHECK(Mret, mysql);
        MYSQL_RES* result = mysql_store_result(mysql);
        MYSQL_ROW row;
        if((row = mysql_fetch_row(result)) == NULL){
            ret = -1;
        }else{
            strcpy(name, row[6]);
        }
    }

    printf("ret = %d, name = %s\n", ret, name);
    //上面的执行完后，若ret等于0则该文件存在，若等于-1则该文件不存在
    getsTextFunc(name, ret, netfd);

    return 0;
}
